from . import passport_blue
from flask import request,jsonify,current_app,make_response
from info.utils.response_code import RET
from info.utils.captcha.captcha import captcha
from info import redis_store
@passport_blue.route('/image_code')
def generate_code():

    image_code = request.args.get('image_code_id')
    print('GET UUID :',image_code)

    if not image_code:
        return jsonify(errno=RET.PARAMERR,errmsg='参数缺失')

    name,text,image = captcha.generate_captcha()

    try:
        redis_store.setex('imagecode_'+image_code,300,text)
    except Exception as e:
        current_app.logger.error('e')
        return jsonify(errno=RET.DBERR,errmsg='存储数据失败')

    resp = make_response(image)
    resp.headers['Content-type']='image/jpg'
    return resp


